<?php

/*
	Class: Communitas_Integrate_Model_Newsletter_Api

	About: Author
		Rich Joslin

	About: License
		<http://communit.as/docs/license>
*/
class Communitas_Integrate_Model_Newsletter_Api extends Mage_Api_Model_Resource_Abstract {

	/*
		Function: isCustomerSubscribed
	*/
	public function isCustomerSubscribed($customer_id) {
		$customer = Mage::getModel('customer/customer')->load($customer_id);
		if (is_null($customer)) {
			$this->_fault('not_exists');
		}
		$subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer);
		if ($subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
			return true;
		} else {
			return false;
		}
	}

	/*
		Function: isEmailSubscribed
	*/
	public function isEmailSubscribed($email_address) {
		$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email_address);
		if ($subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
			return true;
		} else {
			return false;
		}
	}

	/*
		Function: subscribe
	*/
	public function subscribe($email_address) {
		$subscriber = Mage::getModel('newsletter/subscriber');
		return $subscriber->subscribe($email_address);
	}

	/*
		Function: unsubscribe
	*/
	public function unsubscribe($email_address) {
		$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email_address);
		return $subscriber->unsubscribe();
	}

}
